home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / atan.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  912b  |  42 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "pml.h"
  4. #include "cordic.h"
  5.  
  6. static char     funcname[] = "atan";
  7.  
  8. extern CORDIC_Table CORDIC_Table0[1];
  9.  
  10. double
  11. atan(x)
  12.     double          x;
  13. {
  14.     double          x0, y0, z0;
  15.     struct exception xcpt;
  16.  
  17.     if (x < 0.0)
  18.         xcpt.retval = -(atan(-x));
  19.     else if (x > 1.0) {
  20.         if (x < MAXDOUBLE && x > -MAXDOUBLE)
  21.             xcpt.retval = HALFPI - atan(1.0 / x);
  22.         else {
  23.             xcpt.type = UNDERFLOW;
  24.             xcpt.name = funcname;
  25.             xcpt.arg1 = x;
  26.             if (!matherr(&xcpt)) {
  27.                 fprintf(stderr, "%s: UNDERFLOW error\n", funcname);
  28.                 errno = EDOM;
  29.                 xcpt.retval = 0.0;
  30.             }
  31.         }
  32.     }
  33.     else {
  34.         x0 = 1.0;
  35.         y0 = x;
  36.         z0 = 0.0;
  37.         CORDIC_rotate0(0, CORDIC_Table0, &x0, &y0, &z0);
  38.         xcpt.retval = z0;
  39.     }
  40.     return (xcpt.retval);
  41. }
  42.